package com.ruoyi.wx.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wx.domain.AccountInfo;
import com.ruoyi.wx.service.IAccountInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账号信息Controller
 * 
 * @author wt
 * @date 2020-12-13
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wx/accountInfo" )
public class AccountInfoController extends BaseController {

    private final IAccountInfoService iAccountInfoService;

    /**
     * 查询账号信息列表
     */
    @PreAuthorize("@ss.hasPermi('wx:accountInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccountInfo accountInfo)
    {
        startPage();
        LambdaQueryWrapper<AccountInfo> lqw = Wrappers.lambdaQuery(accountInfo);
        if (accountInfo.getAccountId() != null){
            lqw.eq(AccountInfo::getAccountId ,accountInfo.getAccountId());
        }
        if (accountInfo.getRegionId() != null){
            lqw.eq(AccountInfo::getRegionId ,accountInfo.getRegionId());
        }
        if (accountInfo.getSegmentId() != null){
            lqw.eq(AccountInfo::getSegmentId ,accountInfo.getSegmentId());
        }
        if (accountInfo.getModelId() != null){
            lqw.eq(AccountInfo::getModelId ,accountInfo.getModelId());
        }
        if (accountInfo.getState() != null){
            lqw.eq(AccountInfo::getState ,accountInfo.getState());
        }
        if (StringUtils.isNotBlank(accountInfo.getExtInfo())){
            lqw.eq(AccountInfo::getExtInfo ,accountInfo.getExtInfo());
        }
        if (accountInfo.getPrice() != null){
            lqw.eq(AccountInfo::getPrice ,accountInfo.getPrice());
        }
        if (StringUtils.isNotBlank(accountInfo.getSegmentInformation())){
            lqw.eq(AccountInfo::getSegmentInformation ,accountInfo.getSegmentInformation());
        }
        if (StringUtils.isNotBlank(accountInfo.getGameName())){
            lqw.like(AccountInfo::getGameName ,accountInfo.getGameName());
        }
        List<AccountInfo> list = iAccountInfoService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出账号信息列表
     */
    @PreAuthorize("@ss.hasPermi('wx:accountInfo:export')" )
    @Log(title = "账号信息" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(AccountInfo accountInfo) {
        LambdaQueryWrapper<AccountInfo> lqw = new LambdaQueryWrapper<AccountInfo>(accountInfo);
        List<AccountInfo> list = iAccountInfoService.list(lqw);
        ExcelUtil<AccountInfo> util = new ExcelUtil<AccountInfo>(AccountInfo. class);
        return util.exportExcel(list, "accountInfo" );
    }

    /**
     * 获取账号信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('wx:accountInfo:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iAccountInfoService.getById(id));
    }

    /**
     * 新增账号信息
     */
    @PreAuthorize("@ss.hasPermi('wx:accountInfo:add')" )
    @Log(title = "账号信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountInfo accountInfo) {
        return toAjax(iAccountInfoService.save(accountInfo) ? 1 : 0);
    }

    /**
     * 修改账号信息
     */
    @PreAuthorize("@ss.hasPermi('wx:accountInfo:edit')" )
    @Log(title = "账号信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountInfo accountInfo) {
        return toAjax(iAccountInfoService.updateById(accountInfo) ? 1 : 0);
    }

    /**
     * 删除账号信息
     */
    @PreAuthorize("@ss.hasPermi('wx:accountInfo:remove')" )
    @Log(title = "账号信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iAccountInfoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
